﻿using System;

namespace FactoryPattern.SimpleFactory;

public static class SimpleFactory
{
    public abstract class Product
    {
        public abstract void DoSomething();
    }

    public interface IFactoryMethod
    {
        public Product Create();
    }

    public class ConcreteProductA : Product
    {
        public override void DoSomething()
        {
            Console.WriteLine("这里是产品A");
        }
    }

    public class ConcreteProductB : Product
    {
        public override void DoSomething()
        {
            Console.WriteLine("这里是产品B");
        }
    }

    public class ConcreteFactoryA : IFactoryMethod
    {
        public Product Create()
        {
            return new ConcreteProductA();
        }
    }

    public class ConcreteFactoryB : IFactoryMethod
    {
        public Product Create()
        {
            return new ConcreteProductB();
        }
    }

    public static void TestSimpleFactory()
    {
        Console.WriteLine("简单工厂模式：");
        IFactoryMethod factoryA = new ConcreteFactoryA();
        var productA = factoryA.Create();
        IFactoryMethod factoryB = new ConcreteFactoryB();
        var productB = factoryB.Create();
        productA.DoSomething();
        productB.DoSomething();
    }
}